/**
 * 
 */
package service;

import java.util.List;

import utils.Page;

import dao.SeniorAdminDao;
import dao.SeniorAdminDaoImpl;
import exception.ApplicationException;

import model.User;

/**
 * @ClassName: SeniorAdminServiceImpl
 * @Description:
 * @author Hongming Wu
 * @date 2013-12-6
 * 
 */
public class SeniorAdminServiceImpl implements SeniorAdminService {

	@Override
	public void createUser(User user) {
		SeniorAdminDao sad = new SeniorAdminDaoImpl();
		sad.createUser(user);

	}

	@Override
	public User getUserByID(String userID) {
		User user = null;

		try {
			SeniorAdminDao sad = new SeniorAdminDaoImpl();
			user = sad.getUserByID(userID);
		} catch (Exception e) {
			throw new ApplicationException("error!", e);
		}
		return user;
	}

	@Override
	public void updateUser(User user) {
		
		try{
			SeniorAdminDao sad = new SeniorAdminDaoImpl();
			sad.updateUser(user);
		}catch (Exception e) {
			throw new ApplicationException("error!", e);
		}
		
	}

	@Override
	public void removeUser(String userId) {
		try {
			SeniorAdminDao sad = new SeniorAdminDaoImpl();
			sad.deleteUser(userId);
		} catch (Exception e) {
			throw new ApplicationException("error!", e);
		}

	}

	@Override
	public Page loadPagedUsers(Page page, SeniorAdminQueryHelper helper) {

		try {
			SeniorAdminDao sad = new SeniorAdminDaoImpl();
			page.setTotalRecNum(sad.countUsers(helper));
			page.setPageContent(sad.getScopedUser(helper, page.getStartIndex(),
					page.getEndIndex()));
		} catch (Exception e) {
			throw new ApplicationException("error!", e);
		}
		return page;

	}

}
